<template>
  <div>
    <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
      <el-form-item label="上传" prop="field101" required>
        <el-upload ref="field101" :file-list="field101fileList" :action="field101Action"
                   :before-upload="field101BeforeUpload">
          <el-button size="small" type="primary" icon="el-icon-upload">点击上传</el-button>
        </el-upload>
      </el-form-item>
      <el-form-item label="评分" prop="field102">
        <el-rate v-model="formData.field102"></el-rate>
      </el-form-item>
      <el-form-item label="颜色选择" prop="field103" required>
        <el-color-picker v-model="formData.field103" size="medium"></el-color-picker>
      </el-form-item>
      <el-form-item label="日期选择" prop="field104">
        <el-date-picker v-model="formData.field104" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                        :style="{width: '100%'}" placeholder="请选择日期选择" clearable></el-date-picker>
      </el-form-item>
      <el-form-item label="时间选择" prop="field105">
        <el-time-picker v-model="formData.field105" format="HH:mm:ss" value-format="HH:mm:ss"
                        :picker-options='{"selectableRange":"00:00:00-23:59:59"}' :style="{width: '100%'}"
                        placeholder="请选择时间选择" clearable></el-time-picker>
      </el-form-item>
      <el-form-item label="时间范围" prop="field106">
        <el-time-picker v-model="formData.field106" is-range format="HH:mm:ss" value-format="HH:mm:ss"
                        :style="{width: '100%'}" start-placeholder="开始时间" end-placeholder="结束时间" range-separator="至"
                        clearable></el-time-picker>
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  components: {},
  props: [],
  data() {
    return {
      formData: {
        field101: null,
        field102: 0,
        field103: null,
        field104: null,
        field105: null,
        field106: null,
      },
      rules: {
        field102: [{
          required: true,
          message: '评分不能为空',
          trigger: 'change'
        }],
        field104: [{
          required: true,
          message: '请选择日期选择',
          trigger: 'change'
        }],
        field105: [{
          required: true,
          message: '请选择时间选择',
          trigger: 'change'
        }],
        field106: [{
          required: true,
          message: '时间范围不能为空',
          trigger: 'change'
        }],
      },
      field101Action: 'https://jsonplaceholder.typicode.com/posts/',
      field101fileList: [],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        // TODO 提交表单
      })
    },
    resetForm() {
      this.$refs['elForm'].resetFields()
    },
    field101BeforeUpload(file) {
      let isRightSize = file.size / 1024 / 1024 < 2
      if (!isRightSize) {
        this.$message.error('文件大小超过 2MB')
      }
      return isRightSize
    },
  }
}

</script>
<style>
.el-upload__tip {
  line-height: 1.2;
}

.el-rate {
  display: inline-block;
  vertical-align: text-top;
}

</style>
